package com.masterclient.app.modules.order;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselibrary.base.FragmentHostActivity;
import com.eoner.baselibrary.bean.order.ConfirmOrderData;
import com.eoner.baselibrary.bean.order.OrderSendDeliveryBean;
import com.eoner.baselibrary.bean.order.SaleOrderDetailData;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.TimeUtil;
import com.eoner.baselibrary.utils.Utils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.eoner.managerlibrary.router.AroutePath;
import com.eoner.managerlibrary.sobot.SobotManager;
import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.base.ConfirmDialog;
import com.masterclient.app.modules.aftersale.LogistInfoActivity;
import com.masterclient.app.modules.aftersale.adapter.AfterSaleDetailInfoAdapter;
import com.masterclient.app.modules.order.contract.SaleOrderDetailContract;
import com.masterclient.app.modules.order.contract.SaleOrderDetailPresenter;
import com.masterclient.app.widget.PriceIntegralLayout;
import com.sobot.chat.SobotApi;
import com.sobot.chat.api.enumtype.SobotChatTitleDisplayMode;
import com.sobot.chat.api.model.Information;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

//import com.sobot.chat.api.model.OrderCardContentModel;

/**
 * 作者：sean
 * 创建时间：2017/7/27 18:28
 * 功能说明：订单详情
 */
@Route(path = AroutePath.SALE_ORDER_DETAIL_ACTIVITY)
public class SaleOrderDetailActivity extends BaseActivity<SaleOrderDetailPresenter> implements SaleOrderDetailContract.View {



    @BindView(R.id.tv_order_title)
    TextView tvOrderTitle;
    @BindView(R.id.tv_order_subtitle)
    TextView tvOrderSubTitle;
    @BindView(R.id.scroll_view)
    NestedScrollView scrollView;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_tel)
    TextView tvTel;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.ll_shop_container)
    LinearLayout llShopContainer;
    @BindView(R.id.tv_freight)
    TextView tvFreight;
    @BindView(R.id.tv_products_total)
    TextView tvProductsTotal;
    @BindView(R.id.tv_good_info)
    TextView tvGoodInfo;
    @BindView(R.id.ll_final_pay)
    PriceIntegralLayout llFinalPay;
    @BindView(R.id.tv_apply_aftersale)
    TextView tvApplyAfterSale;
    @BindView(R.id.tv_purchase_desc)
    TextView tvPurchaseDesc;
    @BindView(R.id.layout_purchase_desc)
    LinearLayout layoutPurchaseDesc;
    @BindView(R.id.button_purchase_desc)
    TextView buttonPurchaseDesc;
    @BindView(R.id.layout_button_purchase_desc)
    LinearLayout layoutButtonPurchaseDesc;
    @BindView(R.id.layout_order_user)
    View layoutOrderUser;
    @BindView(R.id.iv_order_user_arrow)
    ImageView ivOrderUserArrow;
    @BindView(R.id.tv_order_user_name)
    TextView tvOrderUserName;
    @BindView(R.id.tv_order_user_team)
    TextView tvOrderUserTeam;
    @BindView(R.id.tv_order_user_relation)
    TextView tvOrderUserRelation;
    @BindView(R.id.title_other_info)
    TextView titleOtherInfo;
    @BindView(R.id.recycler_other_info)
    RecyclerView recyclerOtherInfo;
    @BindView(R.id.tv_up_pick)
    TextView tvUpPick;
    @BindView(R.id.tv_sale_logistics)
    TextView tvSaleLogistics;
    @BindView(R.id.tv_up_reserve)
    TextView tvUpReserve;
    @BindView(R.id.tv_send)
    TextView tvSend;
    @BindView(R.id.tv_send_delivery)
    TextView tvSendDelivery;
    @BindView(R.id.tv_again_send)
    TextView tvAgainSend;
    @BindView(R.id.ll_countdown)
    LinearLayout llCountdown;
    @BindView(R.id.tv_countdown)
    TextView tvCountdown;
    @BindView(R.id.sale_order_detail_bottom_line)
    View orderDetailBottomLine;

    @Autowired(name = "order_no")
    String order_no;

    private SaleOrderDetailData orderDetailData;
    private AfterSaleDetailInfoAdapter infoAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sale_order_detail);
        ButterKnife.bind(this);
        ARouter.getInstance().inject(this);

        Utils.setDin(tvCountdown,this);

    }

    @Override
    protected void onResume() {
        mPresenter.getOrderDetail(order_no);
        super.onResume();
    }

    @Override
    public void showOrderDetail(SaleOrderDetailData dataBean) {

        orderDetailData = dataBean;

        tvOrderTitle.setText(dataBean.getTip().getLabel());
        if (TextUtils.isEmpty(dataBean.getTip().getText())){
            tvOrderSubTitle.setVisibility(View.GONE);
        }else {
            tvOrderSubTitle.setText(dataBean.getTip().getText());
            tvOrderSubTitle.setVisibility(View.VISIBLE);
        }

        //地址
        showAddress();

        //描述跳转
        showDescTarget();

        //下单人
        showOrderUser();

        //商品
        showProducts();


        tvProductsTotal.setText("¥ " + dataBean.getProduct_total());
        tvFreight.setText("¥ " + dataBean.getShipping_amount());
        tvApplyAfterSale.setText(dataBean.getShow_refund_btn_text());
        tvApplyAfterSale.setVisibility("1".equals(dataBean.getShow_refund_btn()) ? View.VISIBLE : View.GONE);
        tvGoodInfo.setText(Html.fromHtml("共 <font color=#222222>" + dataBean.getProduct_num() + "</font>" + " 件商品" + "  合计："));
        llFinalPay.setData("0", dataBean.getSubtotal(), true);
        llFinalPay.floadSize(0.88f);

        TimeUtil.orderBtnCountdown(tvCountdown,dataBean.getCount_down_second());
        timerStart();

        //其他信息
        if (orderDetailData.getContent_arr() != null && orderDetailData.getContent_arr().size() > 0) {
            if (infoAdapter == null) {
                recyclerOtherInfo.setLayoutManager(new LinearLayoutManager(this));
                infoAdapter = new AfterSaleDetailInfoAdapter(true);
                infoAdapter.bindToRecyclerView(recyclerOtherInfo);
            }
            infoAdapter.setNewData(orderDetailData.getContent_arr());
            titleOtherInfo.setVisibility(View.VISIBLE);
            recyclerOtherInfo.setVisibility(View.VISIBLE);
        }else {
            titleOtherInfo.setVisibility(View.GONE);
            recyclerOtherInfo.setVisibility(View.GONE);
        }

        //底部按钮
        showBottomButton();

        scrollView.setVisibility(View.VISIBLE);

    }

    private void showAddress(){
        if (orderDetailData.getAddress() != null) {
            tvUserName.setText("收货人：" + orderDetailData.getAddress().getReceiver_name());
            tvAddress.setText(orderDetailData.getAddress().getReceiver_address());
            tvTel.setText(orderDetailData.getAddress().getReceiver_phone());
        }
    }

    private void showDescTarget(){
        if (orderDetailData.getPurchase_tip() != null && !TextUtils.isEmpty(orderDetailData.getPurchase_tip().getText())) {
            if (orderDetailData.getPurchase_tip().getTarget() != null && !TextUtils.isEmpty(orderDetailData.getPurchase_tip().getTarget().getBtn_text())) {
                buttonPurchaseDesc.setText(orderDetailData.getPurchase_tip().getTarget().getBtn_text());
                buttonPurchaseDesc.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
                layoutButtonPurchaseDesc.setVisibility(View.VISIBLE);
            } else {
                layoutButtonPurchaseDesc.setVisibility(View.GONE);
            }
            tvPurchaseDesc.setText(orderDetailData.getPurchase_tip().getText());
            layoutPurchaseDesc.setVisibility(View.VISIBLE);
        }else {
            layoutPurchaseDesc.setVisibility(View.GONE);
        }
    }


    private void showOrderUser(){

        SaleOrderDetailData.BuyerInfoBean buyerInfo = orderDetailData.getBuyer_info();
        if (buyerInfo == null || TextUtils.isEmpty(buyerInfo.getShow_name())){
            layoutOrderUser.setVisibility(View.GONE);
        }else {
            tvOrderUserName.setText(buyerInfo.getShow_name());
            ivOrderUserArrow.setVisibility(TextUtils.isEmpty(buyerInfo.getFans_id())?View.INVISIBLE:View.VISIBLE);
                if (TextUtils.isEmpty(buyerInfo.getFans_txt())){
                    tvOrderUserTeam.setVisibility(View.GONE);
                }else {
                    tvOrderUserTeam.setText(buyerInfo.getFans_txt());
                    tvOrderUserTeam.setVisibility(View.VISIBLE);
                }

                if (TextUtils.isEmpty(buyerInfo.getAgent_txt())){
                    tvOrderUserRelation.setVisibility(View.GONE);
                }else {
                    tvOrderUserRelation.setText(buyerInfo.getAgent_txt());
                    tvOrderUserRelation.setVisibility(View.VISIBLE);
                }
            layoutOrderUser.setVisibility(View.VISIBLE);
        }
    }


    private void showProducts(){

        llShopContainer.removeAllViews();
        for (int i = 0; i < orderDetailData.getProducts().size(); i++) {
            SaleOrderDetailData.ProductsBean shProductsBean = orderDetailData.getProducts().get(i);
            View view = View.inflate(mContext, R.layout.item_good_order_detail, null);
            ViewHolder holder = new ViewHolder(view);

            //提货单
            if (!TextUtils.isEmpty(orderDetailData.getType())&&"27".equals(orderDetailData.getType())){
                holder.layoutPrice.setVisibility(View.GONE);
                holder.tvPickGoodNum.setVisibility(View.VISIBLE);
                holder.tvPickGoodNum.setText("提货数量 "+shProductsBean.getBuy_qty());
            }else {
                holder.layoutPrice.setVisibility(View.VISIBLE);
                holder.tvPickGoodNum.setVisibility(View.GONE);
            }

            ViewTransformUtil.glideImageView(this, shProductsBean.getImage(), holder.ivGood,
                    new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0), R.mipmap.defaults,
                    ScreenUtils.dp2px(107), ScreenUtils.dp2px(107));

            holder.tvGosNum.setText("x" + shProductsBean.getBuy_qty());

                holder.llPrice.setData(shProductsBean.getIntegral(), shProductsBean.getPrice());

            holder.tvTitle.setText(shProductsBean.getName());

//            holder.llSkuContainer.setVisibility(View.GONE);
//            holder.tvSkus.setVisibility(View.VISIBLE);
            holder.tvSkus.setText("规格：" + shProductsBean.getAttribute_desc());
            holder.tvApplyAftersale.setVisibility("1".equals(shProductsBean.getShow_refund_btn()) ? View.VISIBLE : View.GONE);
            holder.tvApplyAftersale.setText(shProductsBean.getShow_refund_btn_text());
            holder.viewLine.setVisibility(orderDetailData.getProducts().size()-1 == i?View.GONE:View.VISIBLE);


            holder.tvApplyAftersale.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Fragment fragment = (Fragment) ARouter.getInstance().build(AroutePath.REFUND_DETAILS_FRAGMENT)
                            .withString("order_id","")
                            .withString("order_product_id",shProductsBean.getOrder_product_id())
                            .navigation();
                    FragmentHostActivity.openFragment(mContext, fragment);
                }
            });

            if (!"3".equals(orderDetailData.getOrder_type())){
                view.setOnClickListener(v -> {
                    ARouter.getInstance().build(AroutePath.PURCHASE_PRODUCT_DETAIL_ACTIVITY)
                            .withString("product_id",shProductsBean.getParent_product_id())
                            .navigation();
                });
            }

            llShopContainer.addView(view);
        }
    }

    private void showBottomButton(){
        tvUpPick.setVisibility(!TextUtils.isEmpty(orderDetailData.getButton().getPick_up_btn())&&"1".equals(orderDetailData.getButton().getPick_up_btn())?View.VISIBLE:View.GONE);
        tvSaleLogistics.setVisibility(!TextUtils.isEmpty(orderDetailData.getButton().getView_track_btn())&&"1".equals(orderDetailData.getButton().getView_track_btn())?View.VISIBLE:View.GONE);
        tvUpReserve.setVisibility(!TextUtils.isEmpty(orderDetailData.getButton().getUp_reserve_btn())&&"1".equals(orderDetailData.getButton().getUp_reserve_btn())?View.VISIBLE:View.GONE);
        tvSend.setVisibility(!TextUtils.isEmpty(orderDetailData.getButton().getSend_btn())&&"1".equals(orderDetailData.getButton().getSend_btn())?View.VISIBLE:View.GONE);
        tvSendDelivery.setVisibility(!TextUtils.isEmpty(orderDetailData.getButton().getDelivery_btn())&&"1".equals(orderDetailData.getButton().getDelivery_btn())?View.VISIBLE:View.GONE);
        tvAgainSend.setVisibility(!TextUtils.isEmpty(orderDetailData.getButton().getAdd_track_btn())&&"1".equals(orderDetailData.getButton().getAdd_track_btn())?View.VISIBLE:View.GONE);
        llCountdown.setVisibility(orderDetailData.getCount_down_second()>0?View.VISIBLE:View.GONE);

        orderDetailBottomLine.setVisibility(tvUpPick.getVisibility() == View.GONE && tvSaleLogistics.getVisibility() == View.GONE &&
                tvUpReserve.getVisibility() == View.GONE && tvSend.getVisibility() == View.GONE && tvSendDelivery.getVisibility() ==
                View.GONE && tvAgainSend.getVisibility() == View.GONE && tvCountdown.getVisibility() == View.GONE?View.GONE:View.VISIBLE);
    }


    private CountDownTimer timer;
    private void timerStart(){
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        if (orderDetailData.getCount_down_second() == 0) return;
        timer = new CountDownTimer(orderDetailData.getCount_down_second() * 1000, 1000) {
            @Override
            public void onTick(long ms) {
                TimeUtil.orderBtnCountdown(tvCountdown,ms/1000);
            }

            @Override
            public void onFinish() {
                if (mPresenter != null) {
                    mPresenter.getOrderDetail(order_no);
                }
            }
        };
        timer.start();
    }

    @OnClick({R.id.layout_countdown,R.id.layout_button_purchase_desc,R.id.layout_order_user,R.id.tv_address_copy, R.id.tv_apply_aftersale, R.id.sale_order_detail_back, R.id.tv_message,
             R.id.tv_up_pick,R.id.tv_sale_logistics,R.id.tv_up_reserve,R.id.tv_send,R.id.tv_send_delivery,R.id.tv_again_send})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_countdown:
                break;
            case R.id.tv_up_pick:
                ConfirmDialog dialogUpPick = new ConfirmDialog(mContext, "使用您在公司仓库保管的库存，给您的买家发货", "取消", "确定","#FF6809");
                dialogUpPick.setOnChooseListerner(new ConfirmDialog.OnChooseListerner() {
                    @Override
                    public void cancel() {
                        dialogUpPick.dismiss();
                    }

                    @Override
                    public void confirm() {
                        mPresenter.checkGoods(orderDetailData.getId(),"pick_up");
                        dialogUpPick.dismiss();
                    }
                });
                dialogUpPick.show();
                break;
            case R.id.tv_sale_logistics:
                if ("4".equals(orderDetailData.getOrder_type())) {
                    //物流列表
                    Fragment fragment = (Fragment) ARouter.getInstance().build(AroutePath.SEND_LOGISTIC_INFO_FRAGMENT)
                            .withString("order_id", orderDetailData.getId())
                            .withString("biz_type", "1")
                            .navigation();
                    FragmentHostActivity.openFragment(mContext, fragment);
                } else {
                    //物流详情
                    startActivitry(LogistInfoActivity.class, new String[][]{{"order_id",  orderDetailData.getId()}, {"track_no", ""}, {"biz_type", "1"}});
                }
                break;
            case R.id.tv_up_reserve:
                showUpReserveDialog();
                break;
            case R.id.tv_send:
                mPresenter.checkGoods( orderDetailData.getId(), "check_send");
                break;
            case R.id.tv_send_delivery:
                ConfirmDialog dialogSendDelivery = new ConfirmDialog(mContext, "给ta充库存后，库存将会划转给下级经销商", "取消", "给ta充库存","#FF6809");
                dialogSendDelivery.setOnChooseListerner(new ConfirmDialog.OnChooseListerner() {
                    @Override
                    public void cancel() {
                        dialogSendDelivery.dismiss();
                    }

                    @Override
                    public void confirm() {
                        mPresenter.checkGoods(orderDetailData.getId(), "delivery_good");
                        dialogSendDelivery.dismiss();
                    }
                });
                dialogSendDelivery.show();
                break;
            case R.id.tv_again_send:
                ARouter.getInstance().build(AroutePath.PURCHASE_SHIPPING_ACTIVITY)
                        .withString("order_id", orderDetailData.getId())
                        .withInt("type", 1).navigation();
                break;
            case R.id.layout_button_purchase_desc:// view_purchase.view_lading 查看提货订单 down_lading 发起提货 to_purchase 下保管订单
                if ("view_lading".equals(orderDetailData.getPurchase_tip().getTarget().getBtn_target())){
                    Intent intentOrderDetail = new Intent(this, OrderDetailActivity.class);
                    intentOrderDetail.putExtra("order_no",orderDetailData.getPurchase_tip().getTarget().getBtn_target_val());
                    intentOrderDetail.putExtra("from_type", "purchase");
                    startActivity(intentOrderDetail);
                }else if ("down_lading".equals(orderDetailData.getPurchase_tip().getTarget().getBtn_target())){
                    mPresenter.checkGoods(orderDetailData.getPurchase_tip().getTarget().getBtn_target_val(),"pick_up");
                }else if ("to_purchase".equals(orderDetailData.getPurchase_tip().getTarget().getBtn_target())){
                    ARouter.getInstance().build(AroutePath.PURCHASE_ACTIVITY).navigation();
                }else if ("view_purchase".equals(orderDetailData.getPurchase_tip().getTarget().getBtn_target())){
                    Intent intentOrderDetail = new Intent(mContext, OrderDetailActivity.class);
                    intentOrderDetail.putExtra("order_no",orderDetailData.getPurchase_tip().getTarget().getBtn_target_val());
                    intentOrderDetail.putExtra("from_type", "purchase");
                    mContext.startActivity(intentOrderDetail);
                }
                break;
            case R.id.layout_order_user:
//                if (orderDetailData.getBuyer_info() == null || TextUtils.isEmpty(orderDetailData.getBuyer_info().getFans_id())) return;
//                ARouter.getInstance().build(AroutePath.VIP_TEAM_DETAILS_ACTIVITY)
//                        .withString("id", orderDetailData.getBuyer_info().getFans_id()).navigation();
                break;
            case R.id.tv_address_copy:
                if (orderDetailData.getAddress() != null && !TextUtils.isEmpty(orderDetailData.getAddress().getReceiver_name())) {
                    StringBuffer addressBuffer = new StringBuffer();
                    addressBuffer.append(orderDetailData.getAddress().getReceiver_name())
                            .append("，")
                            .append(orderDetailData.getAddress().getReceiver_phone())
                            .append("，")
                            .append(orderDetailData.getAddress().getReceiver_address());
                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                    cm.setPrimaryClip(ClipData.newPlainText(null, addressBuffer));
                    showToast("已复制到粘贴板");
                }
                break;
            case R.id.tv_apply_aftersale:
                Fragment fragment = (Fragment) ARouter.getInstance().build(AroutePath.REFUND_DETAILS_FRAGMENT)
                        .withString("order_id",orderDetailData.getId())
                        .withString("order_product_id","")
                        .navigation();
                FragmentHostActivity.openFragment(mContext, fragment);
                break;
            case R.id.sale_order_detail_back:
                finish();
                break;
            case R.id.tv_message:
                Information info = SobotManager.getBaseInfo();
                SobotApi.setChatTitleDisplayMode(this, SobotChatTitleDisplayMode.Default, "");
                SobotApi.setFlowType(this, "0");
                SobotApi.startSobotChat(this, info);
                break;
        }
    }


    @Override
    public void confirm_order_success(ConfirmOrderData data, String sale_type, String buy_type) {
            ARouter.getInstance().build(AroutePath.ORDER_SUBMIT_ACTIVITY)
                    .withString("buy_type", buy_type).
                    withString("saleType", sale_type).
//                    withString("buy_product",new Gson().toJson(dataBean.getSh_tip().getSh_target().getSh_buy_product())).
                    withString("relation_order_id", orderDetailData.getPurchase_tip().getTarget().getBtn_target_val()).
                    withSerializable("confirm_order_data", data).navigation();
    }

    @Override
    public void confirm_order_failed(String msg) {
        ToastUtil.showToast(msg);
    }

    @Override
    public void checkGoodsSuccess(Map<String, String> map) {
        String errorTips = map.get("error_tips");
        String jumpType = map.get("jump_type");
        if (!TextUtils.isEmpty(errorTips)) {
            ConfirmDialog dialog = new ConfirmDialog(getActivity(), "温馨提示", errorTips, null, "取消"
                    , "1".equals(jumpType) ? "去采购" : "2".equals(jumpType) ? "让上级代发" : "确定", "1".equals(jumpType) || "2".equals(jumpType) ? 0 : 1, "#FF6809");
            dialog.setOnChooseListerner(new ConfirmDialog.OnChooseListerner() {
                @Override
                public void cancel() {
                    dialog.dismiss();
                }

                @Override
                public void confirm() {
                    if ("1".equals(jumpType)) {
                        ARouter.getInstance().build(AroutePath.PURCHASE_ACTIVITY).navigation();
                    }else if ("2".equals(jumpType)){
                        showUpReserveDialog();
                    }
                    dialog.dismiss();
                }
            });
            dialog.show();
        } else {
            if ("pick_up".equals(map.get("type"))) {
                ARouter.getInstance().build(AroutePath.ORDER_SUBMIT_ACTIVITY)
                        .withString("buy_type", "2")
                        .withString("saleType", "6")
                        .withString("relation_order_id", map.get("relation_order_id")).navigation();
            }else if ("delivery_good".equals(map.get("type"))){
                mPresenter.sendDelivery(map.get("relation_order_id"));
//            }else if ("pick_up_child".equals(map.get("type"))) {
//                mPresenter.confirm_order(dataBean.getSh_tip().getSh_target().getSh_buy_product() == null ? null : new Gson().toJson(dataBean.getSh_tip().getSh_target().getSh_buy_product())
//                        , "2", "", "6", dataBean.getSh_tip().getSh_target().getSh_order_id(), "0");
            }else {
                ARouter.getInstance().build(AroutePath.PURCHASE_SHIPPING_ACTIVITY)
                        .withString("order_id", map.get("relation_order_id"))
                        .withInt("type", 0).navigation();
            }
        }
    }

    //让上级代发 弹窗
    private void showUpReserveDialog(){
        ConfirmDialog dialogUpReserve = new ConfirmDialog(mContext, "点击确定后，该订单将会自动向上采购", "取消", "确认","#FF6809");
        dialogUpReserve.setOnChooseListerner(new ConfirmDialog.OnChooseListerner() {
            @Override
            public void cancel() {
                dialogUpReserve.dismiss();
            }

            @Override
            public void confirm() {
                mPresenter.upReserve(orderDetailData.getId());
                dialogUpReserve.dismiss();
            }
        });
        dialogUpReserve.show();
    }


    @Override
    public void sendDeliverySuccess(OrderSendDeliveryBean bean) {
        ToastUtil.showToast("拨货成功");
            if (bean != null) {
                OrderSendDeliveryBean.ButtonBean deliveryButtonBean = bean.getOrder_info().getButton();
                orderDetailData.getButton().setAdd_track_btn(deliveryButtonBean.getAdd_track_btn());
                orderDetailData.getButton().setDelivery_btn(deliveryButtonBean.getDelivery_btn());
                orderDetailData.getButton().setPick_up_btn(deliveryButtonBean.getPick_up_btn());
                orderDetailData.getButton().setSend_btn(deliveryButtonBean.getPick_up_btn());
                orderDetailData.getButton().setUp_reserve_btn(deliveryButtonBean.getUp_reserve_btn());
                orderDetailData.getButton().setView_track_btn(deliveryButtonBean.getView_track_btn());
                showBottomButton();
            }
    }

    @Override
    public void operateSuccess(int type) {
        if (type == 0){
            mPresenter.getOrderDetail(order_no);
        }else {

        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
    }

    static class ViewHolder {
        @BindView(R.id.iv_good)
        ImageView ivGood;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_skus)
        TextView tvSkus;
        @BindView(R.id.ll_sku_container)
        LinearLayout llSkuContainer;
        @BindView(R.id.ll_price)
        PriceIntegralLayout llPrice;
        @BindView(R.id.tag_price_vip)
        TextView tagPriceVip;
        @BindView(R.id.tv_gos_num)
        TextView tvGosNum;
        @BindView(R.id.tv_apply_aftersale)
        TextView tvApplyAftersale;
        @BindView(R.id.layout_price)
        View layoutPrice;
        @BindView(R.id.tv_pick_good_num)
        TextView tvPickGoodNum;
        @BindView(R.id.layout_good_desc)
        View layoutGoodDesc;
        @BindView(R.id.tv_good_desc)
        TextView tvGoodDesc;
        @BindView(R.id.view_line)
        View viewLine;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
